<%include file="header.html"%> <%include file="top.html"%> <%include
file="left.html"%>
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script
                type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li><i class="icon-home home-icon"></i> <a
                    href="index.php">首页</a></li>
        </ul>
        <!-- .breadcrumb --></div>

    <div class="page-content">
        <div class="col-xs-12">
            <div class="table-header">
                配置文件列表
            </div>
            <div id="view" class="table-responsive">
                <table id="sample-table-4"
                       class="table table-striped table-bordered table-hover">
                    <form action="" method="post" enctype="multipart/form-data">
                        <tr>
                            <th><input type="file" name="fileUpload" /></th>
                            <th><input type="submit" value="上传新配置文件" />[配置文件必须为xml文件,同时请不要上传文件名带空格及特殊字符的文件]<%$fileUploadMessage%></th>
                        </tr>
                    </form>
                    <tr>
                        <th>配置文件名</th>
                        <th>操作</th>
                    </tr>
                    <%if $configFiles%>
                    <%foreach from=$configFiles item=data%>
                    <tr>
                        <td style="width:25%"><%$data.fileName%></td>
                        <td>
                            <%foreach from = $servers key = key item = value%>
                            <input type="checkbox" name="setServer-<%$data.basename%>" value="<%$value.address%>" />
                            <%$value.name%>
                            <%/foreach%>
                            <button type="button" data-file="<%$data.basename%>" class="btn btn-sm btn-primary setConfig">同步</button>
                        </td>
                    </tr>
                    <%/foreach%>
                    <%/if%>
                </table>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">


    jQuery(function ($) {
        $('.setConfig').on('click',function(){
            var file = $(this).attr('data-file');
            var obj=document.getElementsByName('setServer-'+file);
            var serverIds='';
            for(var i=0; i<obj.length; i++){
                if(obj[i].checked) {serverIds+=obj[i].value+',';} //如果选中，将value添加到变量s中
            }

            if(serverIds==''){
                alert('你还没有选择任何服务器')
                return false
            }
           $.ajax({
                type: "POST",
                url: "index.php?mod=Gm&do=setConfigAjax",
                data: {'file':file,'serverIds':serverIds},
                dataType: 'json',
                success: function(data) {
                    if(data.code != 0){
                        alert(data.msg);
                        return false
                    }else{
                        alert('同步成功')
                    }
                },
                error: function(e) {
                    alert('系统错误,请稍后再试')
                }
            });

        });

    });


</script>
<%include file="footer.html"%>

